Document and Views
Views are usually created in the method Document::DoMakeWindows. A document may have any number of Views showing the document's data in different representations.
A View is usually not directly installed in a window, rather it is put into a Clipper or Scroller in order to show only a part of reasonable size and to allow scrolling. By installing a View in a Splitter or in more than one Scroller different portions of the View can be displayed simultaneously. For example:
Window *MyDocument::DoMakeWindows() { View *view1 = new MyView1 (this /* the next handler */, /* data */); return new Window (this, Point(600,800), eWinDefault, new Expander (cIdNone, eVert, gPoint2, new Scroller (view1), // show view1 in 2 Scrollers new Scroller (view1), // simultaneously new Splitter (new MyView2 (this, /* data */)), NULL ) ); }
A document is always the next event handler of its Views. A View processes user input and passes command objects along the event handler chain to the document. The document executes these commands and this way modifies its data. Dividing the work of displaying, input handling and storing the data is a common practice in ET++ applications and conforms to the MVC (Model-View-Controller) concept introduced by SmallTalk.
Selection and Clipboard
View maintains a current selection. The current selection is a part of the data shown by the View, e.g. a range of text or an element of a list of objects. Commands such as cut, copy and paste are always applied to the current selection. The current selection is additionally drawn highlighted (see Drawing and Selection Highlighting below).
The clipboard is a kind of store where a View can deposit its current selection. Copies of the selection can later be used by the same or by other Views. The cut, copy and paste commands use the clipboard mechanism to exchange data between different Views and even between Views of different applications.
The current selection can be cut or copied to the clipboard and the contents of the clipboard can be pasted into the data structure of the View. Subclasses of View implement cut and copy by overriding the method HasSelection and the method SelectionToClipboard. The paste command can be implemented by overriding the method CanPaste and the method PasteData. HasSelection and CanPaste are actually only used to setup the cut, copy and paste menu items. A good example for implementing the clipboard operations can be found in the class TextView.
Drawing and Selection Highlighting
Drawing and highlighting the current selection is done by overriding the method Draw. For example, a View showing a list of VObjects would implement Draw like this:
class MyView : public View { Collection *list; // a list of VObjects VObject *selected; // currently selected VObject of the list public: .... void Draw (Rectangle); }; void MyView::Draw (Rectangle rect) { Iter next(list); VObject *vop; while (vop = (VObject*) next()) { bool highlight = (vop == selected); vop->DrawAll(rect, highlight); // draw highlighted if it is selected } }The method Update is called before the actual drawing is done. Update gives the possibility to update the View, e.g. to recalculate its layout. See the method DialogView::Update for an example.
classes are always derived from View.
class View
is never reused directly.
class View is abstract.
class View contains 30 methods.
Application Framework